﻿@model XSTDZ.ERP.Application.DataContracts.ProductAllotDto

@{
    ViewBag.Title = " - 更新调拔";
}
@section header{
     <link href="@Url.Content("~/Content/Controls.css")" rel="stylesheet" type="text/css" />
     <link href="@Url.Content("~/Content/Form.css")" rel="stylesheet" type="text/css" />
}
<div class="wp100">

@using (Html.BeginForm())
{
    @Html.ValidationSummary(true)

    <table class="formtable">
    <thead>
        <tr>
            <th colspan="4">@* <h2>新增入库单</h2>*@
            <div id="toptoolbar"></div>
            </th>
        </tr>
    </thead>
    <tr>
       
        <td class="title"> @Html.LabelFor(model => model.AllotNo)</td>
        <td> @Html.TextBoxFor(model => model.AllotNo, new { @class = "text disablebg", @readonly = "readonly" })
        @Html.ValidationMessageFor(model => model.AllotNo)
         <input type="hidden" value="@ViewBag.TempId" id="hidbillDetailId" name="hidbillDetailId"   />
          @Html.HiddenFor(model => model.Id)
          @Html.HiddenFor(model => model.BillState)
        </td>
        <td class="title"></td>
        <td> 
         </td>
  </tr>

  
     <tr>

       <td class="title">@Html.LabelFor(model => model.AllotOrgID)</td>
        <td>  @Html.TextBoxFor(model => model.AllotOrgName, new { @class = "text" })
          @Html.HiddenFor(model => model.AllotOrgID)
            @Html.ValidationMessageFor(model => model.AllotOrgID)
            <a href="javascript:void(0);" onclick="javascript:selectOrg('AllotOrgName','AllotOrgID');" >选择</a>
         </td>
        <td class="title">@Html.LabelFor(model => model.AllotorID)</td>
        <td> 
        @Html.TextBoxFor(model => model.AllotorName, new { @class = "text" })
         @Html.HiddenFor(model => model.AllotorID)
        @Html.ValidationMessageFor(model => model.AllotorID)
        </td>
        
       
  </tr> 

     <tr>
           
          <td class="title">@Html.LabelFor(model => model.FromClientID)</td>
        <td> 
        @Html.TextBoxFor(model => model.FromClientName, new { @class = "text" })
         @Html.HiddenFor(model => model.FromClientID)
        @Html.ValidationMessageFor(model => model.FromClientID)
         <a href="javascript:void(0);" onclick="javascript:selectClient('FromClientName','FromClientID','1');" >选择</a>
        </td>
       
 
         <td class="title"> @Html.LabelFor(model => model.ToClientID)</td>
        <td> @Html.TextBoxFor(model => model.ToClientName, new { @class = "text" })
         @Html.HiddenFor(model => model.ToClientID)
        @Html.ValidationMessageFor(model => model.ToClientID)
         <a href="javascript:void(0);" onclick="javascript:selectClient('ToClientName','ToClientID','0');" >选择</a>
        </td>

</tr>
<tr>
        <td class="title"> @Html.LabelFor(model => model.Remarks)</td>
        <td> @Html.TextBoxFor(model => model.Remarks, new { @class = "text" })
        @Html.ValidationMessageFor(model => model.Remarks)
        </td>
          <td class="title"></td>
        <td> 
         </td>
  </tr> 

     <tr>
        <td  colspan="4">
              <p class="divBtn">
               <input type="hidden" value="" name="hidProductBillItems" id="hidProductBillItems" />
               <input type="hidden" id="hidHttpRefeParent" name="hidHttpRefeParent" value="grid" />
            <input type="button" value="@XSTDZ.ERP.Infrastructure.SystemConfig.BtnSave"  class="BtnSubmit" id="submitBtn" name="submitBtn" />
            <input type="button" value="@XSTDZ.ERP.Infrastructure.SystemConfig.BtnSubmit"  class="BtnSubmit" id="btnSubmit" name="btnSubmit" />
        </p>
        </td>
    </tr>
    </table>
        <input id="HidEmptyGuid" name="HidEmptyGuid" type="hidden" value="@Guid.Empty" />
}
</div>
<div class="wp100">
<div id="ProductAllotItemDetailGrid" style="margin-top:20px" ></div>
<input id="HidOrgCode" name="HidOrgCode" type="hidden" value="@XSTDZ.ERP.Infrastructure.SystemConfig.ChengDuCode" />
<input type="hidden" id="tempHidEmptyDetailId" name="tempHidEmptyDetailId" value="@XSTDZ.ERP.Infrastructure.SystemConfig.emptyGuid" />
</div>
<script type="text/javascript">
    $(document).ready(function () {
        getSelectUserGrid("AllotorName");
        $("#submitBtn").unbind("click").bind("click", function () { getProductBillItemData(false); }); //保存
        $("#btnSubmit").unbind("click").bind("click", function () { getProductBillItemData(true); }); //提交
    });
    function selectOrg(orgName,orgId) {
        var returnValue = window.showModalDialog('../Org/SelectOrgTree?selectType=1', window, "help:No;resizable:No;status:No;scroll:yes;dialogWidth=300px;dialogHeight=300px");
        if (returnValue != null && returnValue != undefined) {
            $("#" + orgName).val(returnValue[0]);
            $("#" + orgId).val(returnValue[1]);
        }
    }
    function selectClient(clientName, clientId,hasseal) {
        var returnValue = window.showModalDialog("../Client/SelectClient?hasSeal=" + hasseal + "&orgCode=@XSTDZ.ERP.Infrastructure.SystemConfig.ChengDuCode", window, "help:No;resizable:No;status:No;scroll:yes;location:No;dialogWidth=800px;dialogHeight=500px");
        if (returnValue != null && returnValue != undefined) {
            $("#" + clientName).val(returnValue[0]);
            $("#" + clientId).val(returnValue[1]);
        }
    }

    function getProductBillItemData(isConfirm) {
        if ($("#BillState").val() == "1") { $.ligerDialog.success("已提交，不能再更新!"); }
        else {
            if (manager != null && manager != undefined) {
                if (!validateGridDetail(manager, "AllotAmount")) { $.ligerDialog.success('明细数量不能小于0!'); return; }; //验证明细
                if (!validateGridDetail(manager, "AllotPrice")) { $.ligerDialog.success('明细单价不能小于0!'); return; }; //验证明细
                var data = manager.getData();
                $("#hidProductBillItems").val("").val(JSON.stringify(data));
                if (!isConfirm) {
                    btnText = $("#submitBtn").val();
                    $("#submitBtn").val("").val("正在处理中...");
                }
                else {
                    btnText = $("#btnSubmit").val();
                    $("#btnSubmit").val("").val("正在处理中...");
                }
                $.ajax({ type: "POST", url: "/ProductAllot/AddAndConfirm?isConfirm=" + isConfirm, data: $('form').serialize(), // 要提交的表单
                    success: function (msg) {
                        if (msg == "9") {
                            $.ligerDialog.success('操作成功!');
                            initligerGrid();
                            ajaxSubmitSuccess(); //公共类：提交成功后关闭当前窗口
                        }
                        else if (msg == "0") {
                            $.ligerDialog.success('数据不完整,请输入必填数据后再提交!');
                        }
                        else if (msg == "-1") {
                            $.ligerDialog.success('调拔明细数据不完整,操作失败!');
                        }
                        else if (msg == "-3") {
                            $.ligerDialog.success('调拔明细调拔数量超过最后一次销售数量,操作失败!');
                        }
                        else {
                            $.ligerDialog.success('操作失败!');
                        }
                        if (!isConfirm) { $("#submitBtn").val("").val(btnText); } else { $("#btnSubmit").val("").val(btnText); }
                    }
                });
            }
        }
    }
</script>

<script type="text/javascript" src="@Url.Content("~/Content/js/SelectData.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Content/js/formBase.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Content/js/ProductAllot/Add.js")"></script>